<?php
namespace Home\Controller;

use Think\Controller;

// 需要登录才能访问的
class SignInController extends BaseController {

    Public function _initialize(){

        parent::_initialize();

        // 没有登录
        $account = $this->getAccount();
        if(empty($account)){
            if (IS_AJAX){
                exit( $this->ajaxLoginError("请登录"));
            }else{
                $this->redirect('/Home/Login/login');
            }
        }
    }

    // 获取账号信息
    function getAccount(){
        // 获取token
        $memberId = $this->get('account')['id'];
        $member = M('member')->where(array("id"=>$memberId, "isDisable"=>2, "isDelete"=>2))->find();
        if ($member){
            session('account', $member);
        } else {
            session('account', null);
        }
        return $this->get('account');
    }

    // 获取账号ID
    function getAccountId(){
        return $this->getAccount()['id'];
    }
}